9 long long cache
[MAXN
+1][MAXN
+1];
11 long long a(const int &i
, const int &j
){
12 if (i
== n
&& j
== 0) return 0;
13 if (i
== n
&& j
== 1) return base
;
15 if (cache
[i
][j
] == -1){
16 long long &r
= cache
[i
][j
] = 0;
19 for (int k
=i
; k
<j
; ++k
){
20 r
= max(r
, a(i
, k
) + a(k
+1, j
));
23 long long x
= 0, y
= 0;
25 for (int k
=i
+1; k
<=n
; ++k
){
26 x
= max(x
, a(k
, 1) + a(k
, j
));
31 for (int k
=1; k
<j
; ++k
){
32 y
= max(y
, a(i
, k
) + a(n
, k
));
42 while (scanf("%d %d", &n
, &base
) == 2){
43 memset(cache
, -1, sizeof cache
);
44 printf("%lld\n", a(1, n
));